import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:yysk_app/model/pay_model/bill_page_model.dart';
import 'package:yysk_app/utils/colors.dart';
import 'package:yysk_app/utils/helper.dart';
import 'package:yysk_app/widget/custom_app_bar2.dart';
import 'package:yysk_app/widget/image_asset_widget.dart';
import 'package:yysk_app/widget/refresh_and_scroll_widget.dart';
import 'bill_detail_controller.dart';
import 'package:yysk_app/widget/custom_app_bar.dart';

class BillDetailPage extends GetView<BillDetailController> {
  static const path = '/billDetail';
  const BillDetailPage({super.key});

  @override
  Widget build(BuildContext context) {
    final double top = MediaQuery.of(context).padding.top;
    return Scaffold(
      body: Stack(
        children: [
          //添加背景色，代码如下：
          SizedBox(
            width: context.width,
            child: ImageAssetWidget(
              width: double.infinity,
              height: 173.px,
              imageUrl: 'static/images/wallet/top_bg.png',
            ),
          ),
          Padding(
            padding: EdgeInsets.fromLTRB(0, top, 0, 24.px),
            child: Column(
              children: [
                CustomAppBar2(title: '账单明细', context: context),
                Expanded(
                  child: Column(
                    children: [
                      Container(
                        // alignment: Alignment.centerLeft,
                        // color: const Color(0xFFE6FFF8),
                        padding: const EdgeInsets.symmetric(
                          horizontal: 24,
                          vertical: 24,
                        ),
                        child: Row(
                          children: [
                            GestureDetector(
                              onTap: controller.showDateFilter,
                              child: Obx(
                                () => Container(
                                  // height: 30.px,
                                  padding: EdgeInsets.fromLTRB(
                                    12.px,
                                    3.px,
                                    13.px,
                                    3.px,
                                  ),
                                  decoration: BoxDecoration(
                                    color: Colors.white,
                                    borderRadius: BorderRadius.circular(20),
                                  ),
                                  alignment: Alignment.center,
                                  child: Row(
                                    mainAxisAlignment: MainAxisAlignment.center,
                                    children: [
                                      Text(
                                        controller.selectedDateRange.value,
                                        style: TextStyle(fontSize: 14.px),
                                      ),
                                      const Icon(
                                        Icons.keyboard_arrow_down_rounded,
                                      ),
                                    ],
                                  ),
                                ),
                              ),
                            ),
                          ],
                        ),
                      ),
                      Expanded(
                        child: Obx(
                          () => Padding(
                            padding: EdgeInsets.fromLTRB(12.px, 0, 12.px, 0),
                            child: RefreshAndScrollWidget(
                              onRefresh: _handleRefresh,
                              scrollController: controller.scrollController,
                              itemBuilder:
                                  (item, index) =>
                                      _listItem(context: context, item: item),
                              itemCount: controller.billList.length,
                              items: controller.billList,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  void _handleRefresh() async {
    controller.getBillList();
  }

  _listItem({required BillPageItem item, required BuildContext context}) {
    return Container(
      padding: EdgeInsets.fromLTRB(27.px, 14.px, 30.px, 14.px),
      margin: EdgeInsets.only(bottom: 12.px),
      decoration: BoxDecoration(
        color: const Color(0xFFF8F8F8),
        borderRadius: BorderRadius.circular(8.px),
      ),
      child: Row(
        crossAxisAlignment: CrossAxisAlignment.center,

        children: [
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Text(
                  '${item.orderInfo}',
                  style: TextStyle(
                    fontSize: 14.px,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                SizedBox(height: 7.px),
                Text(
                  '${item.createTime}',
                  style: TextStyle(fontSize: 12.px, color: Colors.black45),
                ),
              ],
            ),
          ),
          Text(
            '${item.isAdd == false ? '-' : '+'}￥${item.orderAmt}',
            style: TextStyle(
              fontSize: 18.px,
              fontWeight: FontWeight.bold,
              color:
                  item.isAdd == false
                      ? AppColors.fontColorBlack
                      : Color.fromRGBO(12, 163, 90, 1),
            ),
          ),
        ],
      ),
    );
  }
}
